package com.shen.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shen.commonutils.Result;
import com.shen.eduservice.entity.EduCourse;
import com.shen.eduservice.entity.EduTeacher;
import com.shen.eduservice.service.EduCourseService;
import com.shen.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {


    @Autowired
    EduCourseService eduCourseService;
    @Autowired
    EduTeacherService eduTeacherService;
    //查询前8条课程信息 前4条讲师信息
    @GetMapping("index")
    public Result index(){
        QueryWrapper<EduCourse> courseQueryWrapper=new QueryWrapper<>();
        QueryWrapper<EduTeacher> teacherQueryWrapper=new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 8");
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");

        List<EduTeacher> teachers = eduTeacherService.list(teacherQueryWrapper);
        List<EduCourse> courses = eduCourseService.list(courseQueryWrapper);

        return  Result.ok().data("eduList",courses).data("teacherList",teachers);
    }
}
